@import '../../styles/loading';

.s-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: $loading-spinner-color;
  &__spinner {
    position: relative;
    top: 4rpx;
    box-sizing: border-box;
    width: $loading-spinner-size;
    max-width: 100%;
    max-height: 100%;
    height: $loading-spinner-size;
    animation: s-rotate $loading-spinner-animation-duration linear infinite;
    box-sizing: border-box;
    &--spinner {
      animation-timing-function: steps(12);
    }

    &--circular {
      border: 2px solid transparent;
      border-top-color: currentColor;
      border-left-color: currentColor;
      border-radius: 100%;
    }
  }

  &__text {
    margin-left: $padding-mini;
    // color: $loading-text-color;
    font-size: $loading-text-font-size;
    line-height: $loading-text-line-height;

    &:empty {
      display: none;
    }
  }

  &--vertical {
    flex-direction: column;

    .s-loading__text {
      margin: $padding-small;
    }
  }

  &__dot {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    &::before {
      display: block;
      width: 2px;
      height: 26%;
      margin: 0 auto;
      background-color: currentColor;
      border-radius: 40%;
      content: ' ';
    }
  }
}

@mixin generate($n: 12) {
  @for $i from 1 through 12 {
    .s-loading__dot:nth-of-type(#{$i}) {
      transform: rotate($i * 30deg);
      opacity: 1 - (0.75 / 12) * ($i - 1);
    }
  }
}

@include generate(12);

@keyframes s-rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}
